package com.org.controller.pc;

import com.org.DTO.PageDTO;
import com.org.entity.Region;
import com.org.result.Result;
import com.org.service.RegionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 地区控制器
 */
@RestController
@Slf4j
@RequestMapping("/pc")
@RequiredArgsConstructor
public class RegionController {

    private final RegionService regionService;

    /**
     * 查询所有地区
     *
     * @return
     */
    @GetMapping("/findRegion")
    public Result findRegion(PageDTO pageDTO) {
        return Result.success(regionService.findRegion(pageDTO));
    }

    /**
     * 修改区域
     * @param region
     * @return
     */
    @PutMapping("/admin/updateRegion")
    public Result updateRegion(@RequestBody Region region) {
        log.info("修改的区域ID：{}", region.getId());
        regionService.updateRegion(region);
        return Result.success("修改成功");
    }

    /**
     * 添加区域
     * @param region
     * @return
     */
    @PostMapping("/admin/addRegion")
    public Result addRegion(@RequestBody Region region) {
        log.info("添加区域：{}", region);
        regionService.addRegion(region);
        return Result.success("添加成功");
    }

    /**
     * 删除区域
     * @param id
     * @return
     */
    @DeleteMapping("/admin/deleteRegion/{id}")
    public Result deleteRegion(@PathVariable("id") Long id) {
        log.info("删除的区域Id：{}", id);
        regionService.deleteRegion(id);
        return Result.success("删除成功");
    }

}
